﻿using System;

using System.Collections.Generic;
using System.Text;
using Silvermoon.Controls.Base;

namespace Silvermoon.Controls.Classes
{
    public class BubbleButtonCollection : TypedControlCollection<Control, BubbleButton>
    {
        public BubbleButtonCollection(Control owner)
            : base(owner)
        {
        }

        protected Bubble Bubble
        {
            get { return this.Parent as Bubble; }
        }

        protected override void InsertItem(int index, BubbleButton item)
        {
            base.InsertItem(index, item);
            Parent.VisibleControls.AddLast(item);
            Parent.Invalidate(InvalidationFlag.Layout);
        }

        protected override void OnControlRemoved(BubbleButton c)
        {
            base.OnControlRemoved(c);
            Parent.VisibleControls.Remove(c);
            Parent.Invalidate(InvalidationFlag.Layout);
        }


        protected override void ClearItems()
        {
            foreach (BubbleButton b in Items)
            {
                Parent.VisibleControls.Remove(b);
                Parent.Invalidate(InvalidationFlag.Layout);
            }
            base.ClearItems();
        }
    }
}
